home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / tutor / pro18 / nguess.bas < prev    next >
Encoding:
BASIC Source File  |  1991-04-22  |  1.3 KB  |  37 lines

  1. 10 'NGUESS.BAS - to illustrate the 'Top Down' theory of programming
  2. 20 'From the GW-Basic Tutorial Series, GWBT11, 04-30-1991
  3. 30 '
  4. 40 'This program 'thinks' of a random number from 1 to 10 and asks the user
  5. 50 'to guess the number...
  6. 60 GOSUB 1000                   'Randomize and set up
  7. 70 GOSUB 2000                   'Present guess prompt and get guesses
  8. 80 GOSUB 3000                   'See if we want to play again
  9. 90 END                          'End of program
  10. 1000 'Setup and randomizing for number guess...
  11. 1010 RANDOMIZE (-TIMER)
  12. 1020 CLS
  13. 1030 KEY OFF
  14. 1040 LOCATE 3,1,0
  15. 1050 RETURN
  16. 2000 'Think of a number and get the user's guesses...
  17. 2010 NUMBER=INT(RND(1)*10)
  18. 2015 IF NUMBER=0 THEN NUMBER=1
  19. 2020 PRINT "I am thinking of a number between one and ten.  Can you guess it"
  20. 2030 PRINT "within eight tries?"
  21. 2040 COUNTER=1
  22. 2050 PRINT "Guess #";COUNTER;" is:";
  23. 2060 INPUT GUESS
  24. 2070 IF GUESS = NUMBER THEN PRINT "Yes!  You're correct!":RETURN
  25. 2080 PRINT "Nope, sorry!"
  26. 2090 COUNTER=COUNTER+1
  27. 2100 IF COUNTER=9 THEN PRINT "Sorry!  The number was";NUMBER:RETURN
  28. 2110 GOTO 2050
  29. 3000 'See if we are going to play again...
  30. 3010 PRINT
  31. 3020 PRINT "Do you want to try your luck again?  Yes or No."
  32. 3030 LINE INPUT ANSWER$
  33. 3040 ANSWER$=LEFT$(ANSWER$,1)
  34. 3050 'See if it's No
  35. 3060 IF ANSWER$="N" OR ANSWER$="n" THEN END
  36. 3070 RUN
  37.